package com.ruoyi.biz.service.impl;


import com.ruoyi.biz.mapper.LotteryDAO;
import com.ruoyi.biz.dto.LotteryDTO;
import com.ruoyi.biz.entity.LotteryDO;
import com.ruoyi.biz.service.LotteryService;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.util.ValidateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class LotteryServiceImpl implements LotteryService {
    @Resource
    LotteryDAO lotteryDAO;


    @Override
    public List<LotteryDO> queryList(LotteryDTO lotteryDTO) {
        LotteryDO lotteryDO = new LotteryDO();
        BeanUtils.copyBeanProp(lotteryDO, lotteryDTO);
        lotteryDO.setValiFlag("1");
        return lotteryDAO.queryList(lotteryDO);
    }

    @Override
    public int insertLottery(LotteryDTO lotteryDTO) {
        LotteryDO lotteryDO = new LotteryDO();
        BeanUtils.copyBeanProp(lotteryDO, lotteryDTO);
        if (ValidateUtil.isEmpty(lotteryDO.getLotteryCntByPsn())) {
            lotteryDO.setLotteryCntByPsn(1);
        }
        lotteryDO.setLotteryId(IdUtils.simpleUUID().toUpperCase());
        lotteryDO.setValiFlag("1");
        lotteryDO.setUpdtTime(new Date());
        return lotteryDAO.insert(lotteryDO);
    }

    @Override
    public LotteryDTO queryById(String lotteryId) {
        LotteryDO lotteryDO = lotteryDAO.queryById(lotteryId);
        LotteryDTO lotteryDTO = new LotteryDTO();
        BeanUtils.copyBeanProp(lotteryDTO, lotteryDO);
        return lotteryDTO;
    }

    @Override
    public int updateLottery(LotteryDTO lotteryDTO) {
        LotteryDO lotteryDO = new LotteryDO();
        BeanUtils.copyBeanProp(lotteryDO, lotteryDTO);
        lotteryDO.setUpdtTime(new Date());
        return lotteryDAO.update(lotteryDO);
    }

    @Override
    public int deleteLottery(String ids) {
        LotteryDO lotteryDO = new LotteryDO();
        lotteryDO.setUpdtTime(new Date());
        lotteryDO.setLotteryId(ids);
        lotteryDO.setValiFlag("0");
        return lotteryDAO.update(lotteryDO);
    }
}
